<template>
  <div>
    <activity_table
        :data_setting="data_setting"
        :list="list"
        need-ctrl
        @handleGetActivityInfo="handleGetActivityInfo"
    >
      <template slot="ctrl" slot-scope="scope">
        <el-button
            size="medium"
            plain
            type="success"
            @click="handleGoaddArticle(scope.info)"
        >
          活动简报
        </el-button>
      </template>
    </activity_table>

    <el-pagination
        :current-page="currentPage"
        :page-size="currentPageSize"
        :page-sizes="[10, 50, 100, 500, 1000, 99999]"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleGetBySizeActivity"
        @current-change="handleGetByNumActivity"
    />
  </div>
</template>
<script>
import navBtn from "@/components/navBtn";
import Activity_table from "@/components/activity_table";

export default {

  data () {
    return {
      data_setting: [
        { target: "activityType" },
        { target: "communityName" },
        { target: "activityRecruitPeople" },
        { target: "activityCreatedate" },
        { target: "activityDatetime" },
      ],
      list: [],
      currentPage: 1,
      currentPageSize: 10,
      total: 0,
      keyword: "",
      dataRange: null,
      articleContentshow: false,
      sheet_list: [],
      signShow: false,
      signImg: "",
      searchTime: null,
      auditShow: false,
      auditRes: null,
      auditReason: null,
      refuseReason: false,
      articleShow: false,
      tmpActivityId: "",
    };
  },
  mounted () {
    this.handleGetByNumActivity(1);
  },
  components: {
    Activity_table,
    navBtn,
  },
  methods: {
    // 格式化成为表格所需要的数据
    async handleGetBySizeActivity (size) {
      const pageNum = this.currentPage;
      let pageSize = this.currentPageSize;
      pageSize = size;
      const res = await this.$http.activityAll({
        pageNum,
        pageSize,
      });
      if (res.code !== 0) return null;
      this.list = res.data.list;
      this.total = res.data.totalCount;
    },

    // 分页查询全部活动
    async handleGetByNumActivity (num) {
      this.currentPage = num;
      await this.handleGetActivity();
    },
    async handleGetActivityInfo (params) {
      this.$emit("handleGetActivityInfo", params);
    },
    // 分页查询已完成的活动
    async handleGetActivity () {
      const res = await this.$http.activity_allStatus({
        pageNum: this.currentPage,
        pageSize: this.currentPageSize,
        status: 3,
      });
      if (res.code !== 0) return null;
      this.list = res.data.list;
      this.total = res.data.totalCount;
    },
    async handleGoaddArticle (info) {
      // console.log(info)
      await this.$router.push({
        name: "addArticle",
        params: info,
      });
    },
    async handleActivityRecordList (id) {

      const res = await this.$http.activity_recordList(id);
      if (res.code !== 0) return null;

    },

    filterStatus (value, row) {
      return row.activityStatus === value;
    },
    // 筛选是否收费
    filterCharge (value, row) {
      if (value !== 0) return row.activityMoney !== 0;
      return row.activityMoney === value;
    },
  },
};
</script>
